package com.lcj.eduService.controller.front;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.lcj.commonutils.R;
import com.lcj.eduService.entity.EduCourse;
import com.lcj.eduService.entity.EduTeacher;
import com.lcj.eduService.service.EduCourseService;
import com.lcj.eduService.service.EduTeacherService;
import net.bytebuddy.asm.Advice;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author：LCJ
 * @Description：
 * @Date：Create in 14:11 2021/3/22 0022
 */
@RestController
@RequestMapping("eduService/indexFront")
@CrossOrigin
public class IndexFrontController {

    @Autowired
    private EduCourseService courseService;

    @Autowired
    private EduTeacherService teacherService;


    //查询前8条热门课程，前4条名师
    @GetMapping("index")
    public R index(){
        QueryWrapper<EduCourse> courseQueryWrapper = new QueryWrapper<>();
        courseQueryWrapper.orderByDesc("id");
        courseQueryWrapper.last("limit 8");
        List<EduCourse> eduCourses = courseService.list(courseQueryWrapper);

        //查询前4条名师
        QueryWrapper<EduTeacher> teacherQueryWrapper = new QueryWrapper<>();
        teacherQueryWrapper.orderByDesc("id");
        teacherQueryWrapper.last("limit 4");
        List<EduTeacher> teacherList = teacherService.list(teacherQueryWrapper);
        return R.ok().data("courses",eduCourses).data("teachers",teacherList);
    }
}
